using MediatR;
using SumerCoreDevOps.Application.GitTriggers.Commands;
using SumerCoreDevOps.Infrastructure.GitTrigger;

namespace SumerCoreDevOps.Application.GitTriggers.Handlers;

/// <summary>
/// 更新 Git 触发规则命令处理器
/// </summary>
public class UpdateGitTriggerRuleCommandHandler : IRequestHandler<UpdateGitTriggerRuleCommand, Unit>
{
    private readonly GitTriggerRuleManager _ruleManager;

    public UpdateGitTriggerRuleCommandHandler(GitTriggerRuleManager ruleManager)
    {
        _ruleManager = ruleManager;
    }

    public async Task<Unit> Handle(UpdateGitTriggerRuleCommand request, CancellationToken cancellationToken)
    {
        await _ruleManager.UpdateRuleAsync(
            request.Id,
            request.Name,
            request.TriggerType,
            request.BranchPattern,
            request.TagPattern,
            request.PathFilter,
            request.IsEnabled);

        return Unit.Value;
    }
}
